#include "TaskAssigner.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <climits>
#include <chrono>

using namespace std;

//员工数量和任务数量
int numEmployees;
int numTasks;

//从文件加载员工和任务数量以方便初始化对象taskAssigner
void loadDissatisfactionMatrix(const string& filename);

int main()
{
    //计时器开始
    auto start = std::chrono::high_resolution_clock::now();

    //读取员工和任务数量
    loadDissatisfactionMatrix("../generate_samples/dissatisfaction_matrix.txt");

    // 创建任务分配对象
    TaskAssigner taskAssigner(numEmployees, numTasks);
    
    // 从文件加载不满意度矩阵
    taskAssigner.loadDissatisfactionMatrix("../generate_samples/dissatisfaction_matrix.txt");

    // 执行任务分配
    taskAssigner.assignTasks();

    // 显示结果
    taskAssigner.displayResults();

    //计时器终止
    auto stop = std::chrono::high_resolution_clock::now();  
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start).count();  
    std::cout <<endl << "programme elapsed time: " << duration << " ms\n"; 

    system("pause");    //防止终端窗口运行完直接跳掉
    return 0;
}

//从文件加载员工和任务数量以方便初始化对象taskAssigner
void loadDissatisfactionMatrix(const string& filename)
{
    ifstream inputDissatisfaction(filename);
    if (!inputDissatisfaction.is_open())    //检验文件是否正常打开
    {
        cerr << "Error opening file!" << endl;
        return;
    }

    inputDissatisfaction >> numEmployees >> numTasks;   //读取员工数和任务数量

    inputDissatisfaction.close();
}
